package com.icss.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.icss.beans.OverTimeVO;
import com.icss.beans.TravelVO;
import com.icss.daos.OverTimeDao;
import com.icss.daos.TravelDao;

public class OverTimeServlet extends HttpServlet {

	/**
	 * 加班
	 */
	public OverTimeServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        List<OverTimeVO> list=new ArrayList<OverTimeVO>();
        OverTimeDao dao=null;
        String overtime=request.getParameter("overtime");
        System.out.println("程序在OverTimeServlet在doget");
        if(overtime!=null){
        	if(overtime.equals("query")){
        		String sql="select * from overtime";
        		dao=new OverTimeDao();
        		list=dao.selectOvertime(sql);
        		
        		request.setAttribute("overtimeVo", list);
        		String url="/page/attendance/jiaban/overtime_query.jsp";
 			    RequestDispatcher rd=request.getRequestDispatcher(url);
 			    rd.forward(request, response);
        	}
        	
        }
	
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	        request.setCharacterEncoding("utf-8");
	        response.setCharacterEncoding("utf-8");
	        String overtime=request.getParameter("overtime");
	        if(overtime!=null){
	        	OverTimeDao dao=new OverTimeDao();
	        	if(overtime.equals("add")){        		
	        		String personName=request.getParameter("txtName");
	        		String overtimeContent=request.getParameter("txtContent");
	        		Date beginTime = null;  
	        		Date endTime=null;
	                if(request.getParameter("txtDate1")!=null&&request.getParameter("txtDate1")!=""){
	                	beginTime=Date.valueOf(request.getParameter("txtDate1"));
	                } 
	                if(request.getParameter("txtDate2")!=null&&request.getParameter("txtDate2")!=""){
	                	endTime=Date.valueOf(request.getParameter("txtDate2"));
	                }
	        		String shenpiPerson=request.getParameter("sltLeader");	        		
	        		String sql="insert into overtime(personName,overtimeContent,beginTime,endTime,shenpiPerson) values('"+personName+"','"+overtimeContent+"','"+beginTime+"','"+endTime+"','"+shenpiPerson+"')";
	        		dao.insertOvertime(sql);
	        		
	        	}
	        	if(overtime.equals("query")){
	        		
	        		
	        		
	        	}
	        	
	        	
	        	
	        }
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
